package com.b2s.scrumblr.kb.repository;

import com.b2s.scrumblr.kb.model.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.data.solr.repository.Highlight;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;

import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public interface ArticleRepository extends SolrCrudRepository<Article, String>{
    Article findById(String id);

    /**
     * 高亮，高亮字前后加标签，查找内容
     * @param content 查找关键字
     * @param pageable 分页信息
     * @return
     */
    @Highlight(prefix = "<b>", postfix = "</b>")
    HighlightPage<Article> findByContent(String content, Pageable pageable);

    HighlightPage<Article> findByContentLike(String content, Pageable pageable);
    //HighlightPage<Article> findByContentContaining(String content, Pageable pageable);
    Page<Article> findByContentContaining(String content, Pageable pageable);

    @Query("*?0*")
    List<Article> find(String key);

    @Query("?0")
    @Highlight(prefix = "<font color='red'>", postfix = "</font>", fragsize=300)
    HighlightPage<Article> findHighlight(String key, Pageable pageable);

    List<Article> findByCreator(String creator);

    void deleteById(String id);
}
